/**
 * 
 */
package hr.fer.zemris.rznu.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;

import hr.fer.zemris.rznu.model.dao.factories.VirtualBettingDAOFactory;
import hr.fer.zemris.rznu.model.dao.interfaces.IGeneralDAO;
import hr.fer.zemris.rznu.model.dao.interfaces.IVirtualBettingDao;
import hr.fer.zemris.rznu.model.user.Address;
import hr.fer.zemris.rznu.model.user.PersonalUserInfo;
import hr.fer.zemris.rznu.model.user.User;

/**
 * @author Dajan
 *
 */
public class PersistenceTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		IVirtualBettingDao dao = VirtualBettingDAOFactory.createVirtualBettingDAO();
		//Save user
		EntityManager em = dao.getEntityManager();
		em.getTransaction().begin();
		User user = new User();
		user.setUsername("zexinho");
		user.setPassword("ceki");
		
		PersonalUserInfo userInfo = new PersonalUserInfo();
		
		userInfo.setDateOfBirth(new Date());
		userInfo.setEmail("email");
		userInfo.setFirstName("dajan");
		userInfo.setLastName("zvekic");
		userInfo.setMiddleName("tito");
		
		Address address = new Address();
		address.setAddress("andaluzija");
		address.setAddressNumber("12");
		address.setCountry("hrvatska");
		address.setPostNumber("10000");
		address.setTown("andaluzija");
		userInfo.setAddress(address);
		user.setPersonalUserInfo(userInfo);
		
		System.out.println("prosao");
		
		dao.save(user);
		
		
		em.getTransaction().commit();
		
		//Get user by username
//		User user = dao.getUserByUserName("shake");
//		user.setUsername("zex");
//		EntityManager em = dao.getEntityManager();
//		em.getTransaction().begin();
//		dao.update(user);
//		em.getTransaction().commit();
//		System.out.println(user.getUsername());
		
		//Get all users
		List<User> allUsers = new ArrayList<User>(dao.getAllUsers());
		System.out.println(allUsers);
		
		dao.close();
		

	}

}
